<?php

namespace App\Models;

use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User;
use Laravel\Passport\HasApiTokens;

class Members extends User
{
    use SoftDeletes;
    use HasApiTokens;
    protected $table = 'member';
    protected $fillable=[ 'username', 'password', 'email','sex','birthday',
        'avatar','nickname','balance','point','grade_id','status','parent_id' ];

    public function manyPermissions()
    {
        return $this->belongsToMany(Permissions::class,'user_permissions','user_id','permission_id');
    }
    public function manyRoles()
    {
        return $this->belongsToMany(Roles::class,'role_users','user_id','role_id');
    }

    /**
     * @param $username
     * @return mixed
     * 验证phone和email一起验证；在User模型中添加如下方法：
     */
    public function findForPassport($username)
    {
        return $this->orWhere('email', $username)
            ->orWhere('mobile', $username)
            ->orWhere('username', $username)
            ->first();
    }



}
